package com.gm.wj.controller;

import com.gm.wj.dao.UserDAO;
import com.gm.wj.entity.*;
import com.gm.wj.result.Result;
import com.gm.wj.result.ResultFactory;
import com.gm.wj.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * User controller.
 *
 * @author Evan
 * @date 2019/11
 */

@RestController
@Slf4j
public class UserController {
    @Autowired
    UserService userService;

    @Resource
    UserDAO userDAO;

    @Autowired
    AdminUserRoleService adminUserRoleService;

    @GetMapping("/api/admin/user")
    public Result listUsers() {
        return ResultFactory.buildSuccessResult(userService.list());
    }

    @PutMapping("/api/admin/user/status")
    public Result updateUserStatus(@RequestBody @Valid User requestUser) {
        userService.updateUserStatus(requestUser);
        return ResultFactory.buildSuccessResult("用户状态更新成功");
    }

    @PutMapping("/api/admin/user/password")
    public Result resetPassword(@RequestBody @Valid User requestUser) {
        userService.resetPassword(requestUser);
        return ResultFactory.buildSuccessResult("重置密码成功");
    }

    @PutMapping("/api/admin/user")
    public Result editUser(@RequestBody @Valid User requestUser) {
        userService.editUser(requestUser);
        return ResultFactory.buildSuccessResult("修改用户信息成功");
    }

//    @Valid
//    @PostMapping("/api/admin/selectTableNames")
//    @PostMapping("/api/admin/user/selectTableNames")
//    public Result selectTableNames(@RequestBody  User requestUser) {
////        userService.editUser(requestUser);
//        List<Map<String, Object>> maps = userDAO.selectTableNames("wj", "base table");
//        System.out.println(maps);
//        log.info("selectTableNames");
//        log.info("maps {}",maps);
//
//        return ResultFactory.buildSuccessResult(maps);
//    }
}
